//
//  SYS_OrderListCell.m
//  System_App
//
//  Created by 吴健 on 2017/11/29.
//  Copyright © 2017年 czy001. All rights reserved.
//

#import "SYS_OrderListCell.h"

@interface SYS_OrderListCell()
{
    IBOutlet UIImageView *imv_head;
    IBOutlet UILabel     *lb_goodsName;
    IBOutlet UILabel     *lb_price;
    IBOutlet UILabel     *lb_originalPrice;
    IBOutlet UILabel     *lb_specification;
    IBOutlet UILabel     *lb_count;
    IBOutlet UILabel     *lb_installFee;
    IBOutlet NSLayoutConstraint *lc_goodsNameHeight;
    IBOutlet NSLayoutConstraint *lc_priceWidth;
    IBOutlet NSLayoutConstraint *lc_originalPriceWidth;
}
@end

@implementation SYS_OrderListCell

+ (SYS_OrderListCell *)getOrderListCell{
    SYS_OrderListCell *cell = nil;
    NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"SYS_OrderListCell" owner:self options:nil];
    for (NSObject *obj in objects) {
        if ([obj isKindOfClass:[SYS_OrderListCell class]]) {
            cell = (SYS_OrderListCell *)obj;
            break;
        }
    }
    return cell;
}

// iOS 11的 margins
- (UIEdgeInsets)layoutMargins {
    [super layoutMargins];
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

- (void)setItemModel:(OrderItems *)itemModel{
    _itemModel = itemModel;
    [imv_head sd_setImageWithURL:[NSURL URLWithString:_itemModel.logo] placeholderImage:WJIMAGE(@"public_goods")];
    lb_goodsName.text = _itemModel.itemName;
    lb_price.text = FORMAT(@"￥%.2f", _itemModel.price.floatValue);
    //原价
    lb_originalPrice.text = FORMAT(@"￥%.2f", _itemModel.goodsSpecValuesPrice.floatValue);
    lb_originalPrice.attributedText = [[NSAttributedString alloc] initWithString:lb_originalPrice.text attributes:@{NSStrikethroughStyleAttributeName: @(NSUnderlineStyleSingle), NSBaselineOffsetAttributeName: @(0),NSStrikethroughColorAttributeName: WJCOLOR_GRAY, NSFontAttributeName: DSFONT_DETAIL}];
    
    lb_specification.text = _itemModel.specValue;
    lb_count.text = FORMAT(@"x%@", _itemModel.count);
    lb_installFee.text = _itemModel.servicePrice.floatValue == 0?@"": FORMAT(@"安装费：￥%.2f", _itemModel.servicePrice.floatValue);
    lc_priceWidth.constant = [DSUtility getStringWidth:lb_price.text front:DSFONT_DETAIL];
    lc_originalPriceWidth.constant = [DSUtility getStringWidth:lb_originalPrice.text front:DSFONT_DETAIL];
    lc_goodsNameHeight.constant = [DSUtility heightOfString:lb_goodsName.text font:DSFONT_DETAIL width:SCREENWIDTH - 32 -lc_priceWidth.constant maxHeight:40];
    [self updateConstraintsIfNeeded];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
